using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWAARTUM
    {
        public DataRow Convert2WAARTUM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWAARTUM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WAUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WAUADRSLL"] = " ".PadRight(8 ); 
         dwReturn["WAUKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WAUWERK"] = " ".PadRight(3 ); 
         dwReturn["WAUABT"] = " ".PadRight(3 ); 
         dwReturn["WAUART"] = " ".PadRight(20 ); 
         dwReturn["WAUVAR"] = " ".PadRight(2 ); 
         dwReturn["WAUDESS"] = " ".PadRight(10 ); 
         dwReturn["WAUCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["WAUFARBE"] = " ".PadRight(10 ); 
         dwReturn["WAUBESCH"] = " ".PadRight(10 ); 
         dwReturn["WAUARTU"] = " ".PadRight(20 ); 
         dwReturn["WAUVARU"] = " ".PadRight(2 ); 
         dwReturn["WAUDESSU"] = " ".PadRight(10 ); 
         dwReturn["WAUCOLORITU"] = " ".PadRight(10 ); 
         dwReturn["WAUFARBEU"] = " ".PadRight(10 ); 
         dwReturn["WAUBESCHU"] = " ".PadRight(10 ); 
         dwReturn["WAUZUSBEZ"] = " ".PadRight(40 ); 
         dwReturn["WAUARTBEZ"] = " ".PadRight(40 ); 
         dwReturn["WAUFILLER"] = " ".PadRight(46 ); 
         dwReturn["WAUAENDZL"] = " ".PadRight(0 ); 
         dwReturn["WAUAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["WAUAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["WAUNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["WAUNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWAARTUM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWAARTUM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWAARTUM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWAARTUM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWAARTUM(dwLocal, ITXDBVERSION);
            }
            UpdateWAARTUM(dwLocal);
        }
        public void InsertWAARTUM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WAARTUM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWAARTUM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WAARTUM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WAARTUM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WAARTUM";
            Return = Result;
            return Return;
        }
        public void DeleteWAARTUM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WAARTUM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWAARTUM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WAARTUM SET "
                    +"WAUMANDANT= :WAUMANDANT,"
                    +"WAUADRSLL= :WAUADRSLL,"
                    +"WAUKUNDNR= :WAUKUNDNR,"
                    +"WAUWERK= :WAUWERK,"
                    +"WAUABT= :WAUABT,"
                    +"WAUART= :WAUART,"
                    +"WAUVAR= :WAUVAR,"
                    +"WAUDESS= :WAUDESS,"
                    +"WAUCOLORIT= :WAUCOLORIT,"
                    +"WAUFARBE= :WAUFARBE,"
                    +"WAUBESCH= :WAUBESCH,"
                    +"WAUARTU= :WAUARTU,"
                    +"WAUVARU= :WAUVARU,"
                    +"WAUDESSU= :WAUDESSU,"
                    +"WAUCOLORITU= :WAUCOLORITU,"
                    +"WAUFARBEU= :WAUFARBEU,"
                    +"WAUBESCHU= :WAUBESCHU,"
                    +"WAUZUSBEZ= :WAUZUSBEZ,"
                    +"WAUARTBEZ= :WAUARTBEZ,"
                    +"WAUFILLER= :WAUFILLER,"
                    +"WAUAENDZL= :WAUAENDZL,"
                    +"WAUAENDBEN= :WAUAENDBEN,"
                    +"WAUAENDDAT= :WAUAENDDAT,"
                    +"WAUNEUBEN= :WAUNEUBEN,"
                    +"WAUNEUDAT= :WAUNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WAUMANDANT", OracleType.NVarChar).Value = dwData["WAUMANDANT"].ToString(); 
          or1.Parameters.Add("WAUADRSLL", OracleType.NVarChar).Value = dwData["WAUADRSLL"].ToString(); 
          or1.Parameters.Add("WAUKUNDNR", OracleType.NVarChar).Value = dwData["WAUKUNDNR"].ToString(); 
          or1.Parameters.Add("WAUWERK", OracleType.NVarChar).Value = dwData["WAUWERK"].ToString(); 
          or1.Parameters.Add("WAUABT", OracleType.NVarChar).Value = dwData["WAUABT"].ToString(); 
          or1.Parameters.Add("WAUART", OracleType.NVarChar).Value = dwData["WAUART"].ToString(); 
          or1.Parameters.Add("WAUVAR", OracleType.NVarChar).Value = dwData["WAUVAR"].ToString(); 
          or1.Parameters.Add("WAUDESS", OracleType.NVarChar).Value = dwData["WAUDESS"].ToString(); 
          or1.Parameters.Add("WAUCOLORIT", OracleType.NVarChar).Value = dwData["WAUCOLORIT"].ToString(); 
          or1.Parameters.Add("WAUFARBE", OracleType.NVarChar).Value = dwData["WAUFARBE"].ToString(); 
          or1.Parameters.Add("WAUBESCH", OracleType.NVarChar).Value = dwData["WAUBESCH"].ToString(); 
          or1.Parameters.Add("WAUARTU", OracleType.NVarChar).Value = dwData["WAUARTU"].ToString(); 
          or1.Parameters.Add("WAUVARU", OracleType.NVarChar).Value = dwData["WAUVARU"].ToString(); 
          or1.Parameters.Add("WAUDESSU", OracleType.NVarChar).Value = dwData["WAUDESSU"].ToString(); 
          or1.Parameters.Add("WAUCOLORITU", OracleType.NVarChar).Value = dwData["WAUCOLORITU"].ToString(); 
          or1.Parameters.Add("WAUFARBEU", OracleType.NVarChar).Value = dwData["WAUFARBEU"].ToString(); 
          or1.Parameters.Add("WAUBESCHU", OracleType.NVarChar).Value = dwData["WAUBESCHU"].ToString(); 
          or1.Parameters.Add("WAUZUSBEZ", OracleType.NVarChar).Value = dwData["WAUZUSBEZ"].ToString(); 
          or1.Parameters.Add("WAUARTBEZ", OracleType.NVarChar).Value = dwData["WAUARTBEZ"].ToString(); 
          or1.Parameters.Add("WAUFILLER", OracleType.NVarChar).Value = dwData["WAUFILLER"].ToString(); 
          or1.Parameters.Add("WAUAENDZL", OracleType.NVarChar).Value = dwData["WAUAENDZL"].ToString(); 
          or1.Parameters.Add("WAUAENDBEN", OracleType.NVarChar).Value = dwData["WAUAENDBEN"].ToString(); 
          or1.Parameters.Add("WAUAENDDAT", OracleType.NVarChar).Value = dwData["WAUAENDDAT"].ToString(); 
          or1.Parameters.Add("WAUNEUBEN", OracleType.NVarChar).Value = dwData["WAUNEUBEN"].ToString(); 
          or1.Parameters.Add("WAUNEUDAT", OracleType.NVarChar).Value = dwData["WAUNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
